﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KT
{

    public class Log
    {

        public static void Error(string className, string content)
        {
            WriteLog("Error", className, content);
        }
        public static void Info(string className, string content)
        {
            WriteLog("Info", className, content);
        }

        protected static void WriteLog(string logType, string className, string content)
        {
            //写日志到数据库或者文件路径，待定
            string path = AppDomain.CurrentDomain.BaseDirectory;
            if (!Directory.Exists(path))//如果日志目录不存在就创建
            {
                Directory.CreateDirectory(path);
            }

            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");//获取当前系统时间
            string filename = path + logType + "-" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";//用日期对日志文件命名

            //创建或打开日志文件，向日志文件末尾追加记录
            StreamWriter mySw = File.AppendText(filename);

            //向日志文件写入内容
            string write_content = className + " " + time + " : " + content;
            mySw.WriteLine(write_content);

            //关闭日志文件
            mySw.Close();
        }

    }
}
